import provinces from './sampleName.json';
import chinaCitys from './chinaCitys.json'

function getProvinceBySimple(name) {
  return provinces.find(item => item.name === name)
}
function getProvinceByFullName(name) {
  return provinces.find(item => item.fullName === name)
}

function cityToProvince(cityDatas) {
  return chinaCitys.map(item => {
    const cityNames = item.citys.map(item => {
      return item.city
    })
    const datas = cityDatas.reduce((sum, city) => {
      let {deviceCount, faultCount, alarmCount} = sum
      if (cityNames.includes(city.area)) {
        deviceCount += city.deviceCount
        faultCount += city.faultCount
        alarmCount += city.alarmCount
      }
      return {
        deviceCount,
        faultCount,
        alarmCount
      }
    }, {
      deviceCount: 0,
      faultCount: 0,
      alarmCount: 0
    })
    return {
      province: item.province,
      cityNames,
      ...datas
    }
  })
}

export { getProvinceBySimple, getProvinceByFullName, cityToProvince }